<?php

require_once ROOT_DIR.'models/User.php';
require_once ROOT_DIR.'views/UserJSON.php';
require_once ROOT_DIR.'controls/RightHelper.php';


function getUsers($listID = null, $todoID = null, $from = 0, $rows = 30, $sort = 'n', $order = 'asc'){
	
	if(is_null($from)) $from = 0;
	if(is_null($rows)) $rows = 30;
	if(is_null($sort)) $sort = 'n';
	if(is_null($order)) $order = 'asc';
	
	if((!is_null($listID) && RightHelper::sharesList((int)$listID)) || (!is_null($todoID) && RightHelper::checkIfLinkedToTodo((int)$todoID)) || $_SESSION['USER_NAME'] == 'admin' || (is_null($listID) && is_null($todoID))){
		$users = User::getUsers($listID, $todoID, $from, $rows, $sort, $order);
		$count = User::getUserCount($listID, $todoID);
		echo UserJSON::getView($users, $count);
	} else {
		$res = new ResultJSON(true, session_id(), ERROR_NOT_ALLOWED);
		echo $res->renderView();
	}
	
}

?>